<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateTagMapsTable extends Migration 
{
	public function up()
	{
		Schema::create('tag_maps', function(Blueprint $table) {
            $table->increments('id');
            $table->integer('tid')->unsigned();
            $table->integer('aid')->unsigned();
            $table->timestamps();
            $table->foreign('aid')
                ->references('id')
                ->on('articles')
                ->onUpdate('cascade')
                ->onDelete('cascade');
            //tag_id字段作为外键
            $table->foreign('tid')
                ->references('id')
                ->on('tags')
                ->onUpdate('cascade')
                ->onDelete('cascade');
        });
	}

	public function down()
	{
        Schema::table('tag_maps', function(Blueprint $tabel){
            $tabel->dropForeign('tag_maps_aid_foreign');
            $tabel->dropForeign('tag_maps_tid_foreign');
        });
		Schema::drop('tag_maps');
	}
}
